import { useFetch } from "@/http/useFetch";

export const fetchLogin = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/sys/login"
  });
};

export const fetchRegister = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post",
    },
    url: "/sys/saveUser"
  });
};
export const fetchPreRegister = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/add/pre/register"
  });
};

export const fetchUserSearch = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "get"
    },
    url: "/user/search"
  });
};
export const fetchUserListByIds = async function (data?: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "get"
    },
    url: "/user/list"
  });
};
export const fetchUserAdd = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/add"
  });
};
export const fetchUserEnabled = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/update_enabled"
  });
};

export const fetchUserUpdate = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/update"
  });
};
export const fetchUserRemove = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/remove"
  });
};
// 管理员修改密码
export const fetchUserModifyPasswordByRoot = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/user/root/update_password"
  });
};

export const fetchUserLogout = async function (): Promise<any> {
  return await useFetch({
    config: {
      method: "post"
    },
    url: "/login/out"
  });
};
export const fetchUserById = async function (id: number): Promise<any> {
  return await useFetch({
    config: {
      method: "get"
    },
    url: `/user/${id}`
  });
};

export const fetchUpdatePersonal = async function (data: any) {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: `/user/update/personal`
  });
};
export const fetchUpdateUserInfo = async function () {
  return await useFetch({
    config: {
      method: "get"
    },
    url: `/login/me`
  });
};
